//
//  BlockAlertView.m
//  WeiboFun
//
//  Created by luo danal on 8/14/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "BlockAlertView.h"

@implementation BlockAlertView

- (void)dealloc{
    Block_release(_buttonClickBlock);
    self.delegate = nil;
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithTitle:(NSString *)title 
            message:(NSString *)message 
  cancelButtonTitle:(NSString *)cancelButtonTitle 
      okButtonTitle:(NSString *)okButtonTitle{
    
    self = [super initWithTitle:title 
                        message:message 
                       delegate:self 
              cancelButtonTitle:cancelButtonTitle 
              otherButtonTitles:okButtonTitle,nil];
    if (self) {
        
    }
    return self;
}

- (id)initWithTitle:(NSString *)title 
            message:(NSString *)message 
  cancelButtonTitle:(NSString *)cancelButtonTitle 
      okButtonTitle:(NSString *)okButtonTitle 
   buttonClickBlock:(void (^)(int))block{
    
    self = [super initWithTitle:title 
                        message:message 
                       delegate:self 
              cancelButtonTitle:cancelButtonTitle 
              otherButtonTitles:okButtonTitle,nil];
    if (self) {
        [self setButtonClickBlock:block];
    }
    return self;
}

- (void)setButtonClickBlock:(void (^)(int buttonIndex))block{
    Block_release(_buttonClickBlock);
    _buttonClickBlock = Block_copy(block);
}

#pragma mark - Delegate

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (_buttonClickBlock != NULL) {
        _buttonClickBlock(buttonIndex);
    }
}

@end
